﻿
Partial Class GenFctParent
    Inherits System.Web.UI.Page

   
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        Dim adapter As New FundCenterParentTableAdapters.FctParentTableAdapter
        Dim Hadapter As New FundCenterParentTableAdapters.FctHTableAdapter
        Dim Hdatatable As New FundCenterParent.FctHDataTable
        adapter.DeleteByYear(Val(Session("planyear")))
        Hdatatable = Hadapter.GetData(Val(Session("planyear")))
        Dim FctCode As String
        For Each row As FundCenterParent.FctHRow In Hdatatable
            FctCode = row.FundCenter_FundCenterCode
            adapter.InsertQuery(FctCode, Val(Session("planyear")))
        Next
        SetParent("01")
        Response.Write("Done")
    End Sub
    Sub SetParent(GroupPath As String)
        Dim adapter As New FundCenterParentTableAdapters.FctParentTableAdapter
        Dim Hadapter As New FundCenterParentTableAdapters.FctHTableAdapter
        Dim Hdatatable As New FundCenterParent.FctHDataTable
        Dim level As Integer
        level = Len(GroupPath) / 2
        Hdatatable = Hadapter.GetDataByGPath(GroupPath, Val(Session("planyear")))
       
        Dim FctCode As String
        Dim description As String
        For Each row As FundCenterParent.FctHRow In Hdatatable
            FctCode = row.FundCenter_FundCenterCode
            description = row.Description
           
        Next
        Hdatatable = Hadapter.GetDataByLikeGPath(GroupPath & "%", Val(Session("planyear")))
        For Each row As FundCenterParent.FctHRow In Hdatatable
            If level = 1 Then
                adapter.UpdateParent1(FctCode, description, row.FundCenter_FundCenterCode)
            ElseIf level = 2 Then
                adapter.UpdateParent2(FctCode, description, row.FundCenter_FundCenterCode)
            ElseIf level = 3 Then
                adapter.UpdateParent3(FctCode, description, row.FundCenter_FundCenterCode)
            ElseIf level = 4 Then
                adapter.UpdateParent4(FctCode, description, row.FundCenter_FundCenterCode)
            ElseIf level = 5 Then
                adapter.UpdateParent5(FctCode, description, row.FundCenter_FundCenterCode)
            End If
            If row.grouppath <> GroupPath Then
                SetParent(row.grouppath)
            End If

        Next
    End Sub
End Class
